~ chicken-core (chicken-5) /manual/Extensions to the standard
Trap1[[tags: manual]]23[[toc:]]45== Extensions to the R5RS standard67=== Identifiers89Identifiers may contain special characters if delimited with10{{| ... |}}.1112=== Brackets and braces1314The brackets {{[ ... ]}} and the braces {{ { ... } }} are15provided as an alternative syntax for {{( ... )}}. A number of reader16extensions is provided.1718=== Non-standard procedures and syntax1920CHICKEN provides numerous non-standard procedures. See the manual21sections on the included library modules ([[Included modules]]) for22more information. Here we only document {{cond-expand}} because it is23always present in a module, even without imports.2425==== cond-expand2627<macro>(cond-expand FEATURE-CLAUSE ...)</macro>2829Expands by selecting feature clauses. This form is allowed to appear in non-toplevel expressions.3031Predefined feature-identifiers are "situation" specific:3233; compile : {{chicken}}, {{chicken-5}}, {{compiling}}, {{library}}, {{eval}}, {{extras}}, {{regex}}, {{srfi-0}}, {{srfi-2}}, {{srfi-4}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-11}}, {{srfi-12}}, {{srfi-15}}, {{srfi-16}}, {{srfi-17}}, {{srfi-23}}, {{srfi-26}}, {{srfi-28}}, {{srfi-30}}, {{srfi-31}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}3435; load : {{chicken}}, {{chicken-5}}, {{extras}}, {{srfi-0}}, {{srfi-2}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-12}}, {{srfi-17}}, {{srfi-23}}, {{srfi-28}}, {{srfi-30}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}. {{library}} is implicit.3637; eval : {{csi}}, {{chicken}}, {{chicken-5}}, {{extras}}, {{srfi-0}}, {{srfi-2}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-11}}, {{srfi-12}}, {{srfi-15}}, {{srfi-16}}, {{srfi-17}}, {{srfi-23}}, {{srfi-26}}, {{srfi-28}}, {{srfi-30}}, {{srfi-31}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}. {{library}} is implicit.3839Also, features of the form {{chicken-5.X}}, where {{X}} denotes the minor version, are available.4041The symbols returned by the following procedures from [[Module (chicken platform)|(chicken platform)]] are also available as feature-identifiers in all situations: {{(machine-byte-order)}}, {{(machine-type)}}, {{(software-type)}}, {{(software-version)}}. For example, the {{machine-type}} class of feature-identifiers include {{arm}},42{{alpha}}, {{mips}}, etc.4344The [[Module (chicken platform)|(chicken platform)]] module also provides a function {{(features)}} that returns a list of all registered features.4546In addition the following feature-identifiers may exist: {{cross-chicken}}, {{dload}}, {{manyargs}}, {{ptables}}.4748For further information, see the documentation for49[[http://srfi.schemers.org/srfi-0/srfi-0.html|SRFI-0]].505152=== User defined character names5354User defined character names are supported. See55{{char-name}}. Characters can be given56in hexadecimal notation using the ''#\xXX'' syntax where ''XX'' specifies the57character code. Character codes above 255 are supported and can be read (and are58written) using the ''#\uXXXX'' and ''#\UXXXXXXXX'' notations.5960Non-standard characters names supported are {{#\tab}}, {{#\linefeed}}, {{#\return}}, {{#\alarm}},61{{#\vtab}}, {{#\nul}}, {{#\page}}, {{#\esc}}, {{#\delete}} and {{#\backspace}}.6263=== Special characters in strings6465CHICKEN supports special characters preceded with66a backslash ''\'' in quoted string67constants. ''\n'' denotes the newline-character,68''\r'' carriage return, ''\b''69backspace, ''\t'' TAB, ''\v'' vertical TAB, ''\a'' alarm, ''\f'' formfeed,70''\xXX'' a character with the code {{XX}} in hex and71''\uXXXX'' (and ''\UXXXXXXXX'') a unicode character with the code {{XXXX}}.72The latter is encoded in UTF-8 format.7374== Non-standard read syntax7576=== Escapes in symbols7778{{| ... |}} may be used to escape a sequence of characters when reading a symbol.79{{\X}} escapes a single character in a symbols name:8081 (symbol->string '|abc def|) => "abc def"82 (symbol->string '|abc||def|) => "abcdef"83 (symbol->string '|abc|xyz|def|) => "abcxyzdef"84 (symbol->string '|abc\|def|) => "abc|def"85 (symbol->string 'abc\ def) => "abc def"8687=== Multiline Block Comment8889<read>#|</read>9091 #| ... |#9293A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].9495=== Expression Comment9697<read>#;</read>9899 #;EXPRESSION100101Treats {{EXPRESSION}} as a comment. That is, the comment runs through the whole S-expression, regardless of newlines, which saves you from having to comment out every line, or add a newline in the middle of your parens to make the commenting of the last line work, or other things like that. Implements [[http://srfi.schemers.org/srfi-62/srfi-62.html|SRFI-62]].102103=== External Representation104105<read>#,</read>106107 #,(CONSTRUCTORNAME DATUM ...)108109Allows user-defined extension of external representations. (For more information see the documentation for110[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])111112=== Location Expression113114<read> #$EXPRESSION</read>115116An abbreviation for {{(location EXPRESSION)}}.117118=== Blob literals119120<read>#${</read>121122 #${ HEX ... }123124Syntax for literal "blobs" (byte-sequences). Expects hexadecimal digits and ignores125any whitespace characters:126127 #;1> ,d '#${deadbee f}128 blob of size 4:129 0: de ad be ef ....130131=== Keyword132133<read>#:</read>134135 #:SYMBOL136 SYMBOL:137 :SYMBOL138139Syntax for keywords. Keywords are symbol-like objects that evaluate to themselves, and as such don't have to be quoted. Either {{SYMBOL:}} or {{:SYMBOL}} is accepted, depending on the setting of the {{keyword-style}} parameter, but never both. {{#:SYMBOL}} is always accepted.140141=== Multiline String Constant142143<read>#<<</read>144145 #<<TAG146147Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:148149 (define msg #<<END150 "Hello, world!", she said.151 END152 )153154is equivalent to155156 (define msg "\"Hello, world!\", she said.")157158=== Multiline String Constant with Embedded Expressions159160<read>#<#</read>161162 #<#TAG163164Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:165166 (define three 3)167 (display #<#EOF168 This is a simple string with an embedded `##' character169 and substituted expressions: (+ three 99) ==> #(+ three 99)170 (three is "#{three}")171 EOF172 )173174prints175176 This is a simple string with an embedded `#' character177 and substituted expressions: (+ three 99) ==> 102178 (three is "3")179180=== Foreign Declare181182<read>#></read>183184 #> ... <#185186Abbreviation for {{(foreign-declare " ... ")}}.187188=== String escape sequences189190String-literals may contain the following escape sequences:191192<table style="margin-top: 1em; max-width: 40em">193<tr><th>Escape sequence</th><th>Character</th></tr>194<tr><td>{{\n}}</td><td>line feed / newline</td></tr>195<tr><td>{{\t}}</td><td>tab</td></tr>196<tr><td>{{\r}}</td><td>carriage return</td></tr>197<tr><td>{{\b}}</td><td>backspace</td></tr>198<tr><td>{{\a}}</td><td>bell</td></tr>199<tr><td>{{\v}}</td><td>vertical tab</td></tr>200<tr><td>{{\f}}</td><td>form feed</td></tr>201<tr><td>{{\x}}''XX''</td><td>hexadecimal 8-bit character code</td></tr>202<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>203<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>204<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>205<tr><td>{{\|}} {{\"}} {{\\}} {{\'}}</td><td>the escaped character</td></tr>206</table>207208209=== Bang210211<read>#!</read>212213 #!...214215Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.216217; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored218219; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned220221; DSSSL Formal Parameter List Annotation : If followed by any of the character sequences {{optional}}, {{rest}} or {{key}}, then a symbol with the same name (and prefixed with {{#!}}) is returned222223; Read Mark Invocation : If a ''read mark'' with the same name as the token is registered, then its procedure is called and the result of the read-mark procedure will be returned224225=== Case Sensitive Expression226227<read>#cs</read>228229 #cs...230231Read the next expression in case-sensitive mode (regardless of the current global setting).232233=== Case Insensitive Expression234235<read>#ci</read>236237 #ci...238239Read the next expression in case-insensitive mode (regardless of the current global setting).240241=== Conditional Expansion242243<read>#+</read>244245 #+FEATURE EXPR246247Rewrites to248249 (cond-expand (FEATURE EXPR) (else))250251and performs the feature test at macroexpansion time. Therefore, it may not252work as expected when used within a macro form.253254---255Previous: [[Deviations from the standard]]256257Next: [[Debugging]]